package com.zxh.zhenxihuan.service.impl;

import com.zxh.zhenxihuan.entity.ShangJia;
import com.zxh.zhenxihuan.mapper.ShangjiaMapper;

import com.zxh.zhenxihuan.service.ShangjiaService;
import com.zxh.zhenxihuan.util.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("shangjiaService")
public class ShangjiaServiceImpl implements ShangjiaService {
    @Resource
    ShangjiaMapper shangjiaMapper;

    @Override
    public Integer getSum() {
        return shangjiaMapper.getSum();
    }

    @Override
    public List<ShangJia> find_shangjia(Integer start, Integer end) {
        List<ShangJia> list=shangjiaMapper.find_shangjia(start,end);
        for(ShangJia m:list){
            System.out.println(m);
        }
        return list;
    }

    @Override
    public Map<String, Object> getShangjiaPage(Integer num, Integer count) {
        Integer pageNum=1;
        try {
            pageNum=Integer.valueOf(num);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        Integer pageCount=5;
        try {
            pageCount=Integer.valueOf(count);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        Page<ShangJia> page =new Page();
        page.init(pageNum,pageCount,getSum());
        page.setList(find_shangjia(page.getRowNum(),pageCount));
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        return map;
    }
}
